﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameEngine.DrawEvaluator
{
    /// <summary>
    /// Draw evaluator for international checkers 
    /// </summary>
    public class InternationalDrawEvaluator: DrawEvaluator
    {
        /// <summary>
        /// Maximum number of moves for international checkers
        /// </summary>
        private const int keyInternationMaximumNumberOfMoves = 25;

        /// <summary>
        /// Overrided maximum number of moves
        /// </summary>
        protected override int MaximumNumberOfMoves
        {
            get
            {
                return keyInternationMaximumNumberOfMoves;
            }
        }

        /// <summary>
        /// Checks special positions for internation checkers
        /// </summary>
        protected override int? IsSpecialPosition()
        {
            FigureCounts cnt = GetCurrentFigureCounts();

            int menCount = 0;
            int kingCount = 0;

            // check if there is one king on one side
            if (cnt.WKCnt == 1 && cnt.WMCnt == 0)
            {
                menCount = cnt.BMCnt;
                kingCount = cnt.BKCnt;
            }
            else if (cnt.BKCnt == 1 && cnt.BMCnt == 0)
            {
                menCount = cnt.WMCnt;
                kingCount = cnt.WKCnt;
            }
            else return null;

            if ((kingCount == 1 && (menCount == 0 || menCount == 1))
                || (kingCount == 2 && menCount == 0))
            {
                return 5;
            }

            if( (kingCount == 3 && menCount == 0)
                || (kingCount == 2 && menCount == 1)
                || (kingCount == 1 && menCount == 2))
            {
                return 16;
            }

            return null;
        }
    }
}
